using System;
using System.Collections.Generic;
using System.Text;

namespace WP.Commons
{
    public class ControlArray<T> where T : System.Windows.Forms.Control
    {
        System.Collections.Generic.List<T> _List ;
        public ControlArray()
        {
            _List = new List<T>();
        }
        
        public void Add(T t) 
        {
            this._List.Add(t);
            
        }

        /// <summary>
        /// Get Control
        /// </summary>
        /// <param name="Index">Control's index</param>
        /// <returns></returns>
        public T this[int Index]
        {
            get
            {
                return (T)this._List[Index];
            }
        }

        /// <summary>
        /// Get Control
        /// </summary>
        /// <param name="strName">Control's name</param>
        /// <returns></returns>
        public T this[string strName]
        {
            get
            {
                for (int i = 0; i < this._List.Count; i++)
                {
                    if (this._List[i]!=null && this._List[i].Name.TrimEnd().ToUpper() == strName.TrimEnd().ToUpper()) return (T)this._List[i];
                }
                return null;
            }
        }

        /// <summary>
        /// Get Control Index
        /// </summary>
        /// <param name="t">Control</param>
        /// <returns></returns>
        public int this[T t]
        {
            get
            {
                for (int i = 0; i < this._List.Count; i++)
                {
                    
                    if (this._List[i]!=null && this._List[i].Name == t.Name) return i;
                }
                return -1;
            }
        }

    }
}
